<?php
/**
 *  extention.func.php 用户自定义函数库
 *
 * @copyright			(C) 2005-2010 PHPCMS
 * @license				http://www.phpcms.cn/license/
 * @lastmodify			2010-10-27
 */

/**判断用户是否已经登录
 * @return string
 */
function logined()
{
    $phpcms_auth = param::get_cookie('auth');
    if($phpcms_auth)
    {
        return '1';
    }
    else
    {
        return '-1';
    }
}

/**判断图书是否已经购买过
 * @param $bookid
 * @return bool
 */
function hasPayment($bookid)
{
    $phpcms_auth = param::get_cookie('auth');
    if($phpcms_auth)
    {
        $db = pc_base::load_model('book_model');
        $userid = param::get_cookie('_userid');
        $sql = 'SELECT * FROM `v9_bookbuy_records` WHERE user_id = '.$userid.' AND book_id = '.$bookid;
        $db->query($sql);
        $rows = $db->fetch_array();
        $count = count($rows);
        if($count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

/**判断图片是否已经购买过
 * @param $picid
 * @param $type
 * @return bool
 */
function hasPaymentPicture($picid,$type)
{
    $phpcms_auth = param::get_cookie('auth');
    if($phpcms_auth)
    {
        $db = pc_base::load_model('picturebuy_records_model');
        $userid = param::get_cookie('_userid');
        $where = array("picture_id"=>$picid,"user_id"=>$userid,"type"=>$type);
        $res = $db->get_one($where);
        if($res)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

?>